package geguol.cc.widgetapplication.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Html;
import android.widget.RadioButton;
import android.widget.TextView;

import org.sufficientlysecure.htmltextview.HtmlResImageGetter;
import org.sufficientlysecure.htmltextview.HtmlTextView;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringReader;

import geguol.cc.widgetapplication.R;
/**
 * 显示一个 文本
 * */
public class TvLoadHtmlActivity extends AppCompatActivity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_tv_load_html);
		HtmlTextView textView = (HtmlTextView) findViewById(R.id.textView);
		RadioButton radioButton = (RadioButton) findViewById(R.id.bb);
//		radioButton.setOnCheckedChangeListener();

		String html = null;
		try {
			int len=0;
			StringBuffer str=new StringBuffer("");
			
			InputStream is = getAssets().open("paper.html");
			Reader in=new InputStreamReader(is);
			BufferedReader bufferedReader = new BufferedReader(in);
			String line=null;

			while( (line=bufferedReader.readLine())!=null ) {
				if(len != 0)  // 处理换行符的问题
				{
					str.append("\r\n"+line);
				} else {
					str.append(line);
				}
				len++;
			}
			in.close();
			is.close();
			html = str.toString();
		} catch (IOException e) {
			e.printStackTrace();
		}

		textView.setHtml(html,new HtmlResImageGetter(textView));
	}
}
